﻿using Jacobi.Seesmic.FeedReader.Utilities;

namespace Jacobi.Seesmic.FeedReader.Model
{
    /// <summary>
    /// Manages the configuration settings for a single feed.
    /// </summary>
    /// <remarks>Must be public for xml serialization.</remarks>
    public sealed class FeedInfo : ObservableBase
    {
        internal const string UrlPropertyName = "Url";
        internal const string FeedTypePropertyName = "FeedType";
        internal const string EnabledPropertyName = "Enabled";
        internal const string MaxItemCountPropertyName = "MaxItemCount";

        /// <summary>
        /// Public constructor for xml serialization support.
        /// </summary>
        public FeedInfo()
        { }

        /// <summary>
        /// Copy constructor.
        /// </summary>
        /// <param name="copy">Must not be null.</param>
        internal FeedInfo(FeedInfo copy)
        {
            Assign(copy);
        }

        /// <summary>
        /// Assigns all property values of <paramref name="copy"/> to this.
        /// </summary>
        /// <param name="copy">Must not be null.</param>
        internal void Assign(FeedInfo copy)
        {
            copy.ThrowIfArgumentIsNull("copy");

            Url = copy.Url;
            FeedType = copy.FeedType;
            Enabled = copy.Enabled;
            MaxItemCount = copy.MaxItemCount;
        }

        private string _url;

        /// <summary>
        /// Gets or sets the url of the feed.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings",
            Justification = "By design")]
        public string Url
        {
            get { return _url; }
            set
            {
                SetPropertyValue(ref _url, value, UrlPropertyName);
            }
        }

        private string _feedType;

        /// <summary>
        /// Gets or sets the type of the feed (Atom10/Rss20).
        /// </summary>
        /// <remarks>
        /// Refer to <see cref="T:System.ServiceModel.Syndication.SyndicationVersions"/> for valid values.
        /// </remarks>
        public string FeedType
        {
            get { return _feedType; }
            set
            {
                SetPropertyValue(ref _feedType, value, FeedTypePropertyName);
            }
        }

        private bool _enabled;

        /// <summary>
        /// Gets or sets an indication if the feed is enabled.
        /// </summary>
        public bool Enabled
        {
            get { return _enabled; }
            set
            {
                SetPropertyValue(ref _enabled, value, EnabledPropertyName);
            }
        }

        private int _maxItemCount;

        /// <summary>
        /// Gets or sets the maximum number of items that are published to the timeline.
        /// </summary>
        public int MaxItemCount
        {
            get { return _maxItemCount; }
            set
            {
                SetPropertyValue(ref _maxItemCount, value, MaxItemCountPropertyName);
            }
        }
    }
}